import java.util.Arrays;
import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/14
 */
public class demo3 {
    public static void main (String[] args) {
        //滑动窗口
        //维护窗⼝内最⼤值与最⼩值的差在 2 * p 之间

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int p = scanner.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        Arrays.sort(a);

        int left = 0, right = 0, num = 0;
        p *= 2;

        while (right < n){
            while (a[right] - a[left] > p){
                left++;
            }
            num = Math.max(num, right - left +1);
            right++;
        }
        System.out.println(num);
    }
}
